﻿using System.Web.UI;
using DMS.BaseClass;

namespace DMS.Business.Modules.WorkFlow
{
    public class FormBase: UserControl
    {
        //需要控制权限的控件
        protected object[] controls = new object[0];
        private string appCaseID;
        public string AppCaseID
        {
            get { return appCaseID; }
            set
            {
                appCaseID = value;
            }
        }
        public virtual string Title
        {
            get{
                return "";
            }
        }
        private string stepName;

        public string StepName
        {
            get { return stepName; }
            set { stepName = value; }
        }
        private int actionType;

        public int ActionType
        {
            get { return actionType; }
            set { actionType = value; }
        }
        public virtual void InitForm()
        {
        }
        public virtual void Save()
        {
            if (string.IsNullOrEmpty(Request.QueryString["instanceID"]))
                AddFormData();
            else
                UpdateFormData();

            AfterSaveFormData();

            if (this.StepName == "结束")
            {
                AfterFinishWorkflow();
            }
        }

        /// <summary>
        /// 是否新建流程
        /// </summary>
        public bool IsNewFlow
        {
            get
            {
                return string.IsNullOrEmpty(Request.QueryString["instanceID"]);
            }
        }


        /// <summary>
        /// 添加表单数据
        /// </summary>
        public virtual void AddFormData()
        {
        }
        /// <summary>
        /// 更新表单数据
        /// </summary>
        public virtual void UpdateFormData()
        {
        }

        /// <summary>
        /// 保存表单数据后的操作
        /// </summary>
        public virtual void AfterSaveFormData()
        {
        }

        /// <summary>
        /// 流程结束后的操作
        /// </summary>
        public virtual void AfterFinishWorkflow()
        {
        }

        public virtual void SetSecurity()
        {
            UISecurity.SetSecurity(controls, stepName, actionType);
        }



        public virtual string Condition
        {
            get
            {
                return "";
            }
        }

        
        
    }
}
